{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3ddf45c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5c36ee48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5514885275227519"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3a9604c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "35"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,67)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c787187e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This second seems a little odd.\n",
      "Not an odd second.\n",
      "This second seems a little odd.\n",
      "This second seems a little odd.\n",
      "This second seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import time\n",
    "import random\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "         print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "         print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5) # 间隔\n",
    "    time.sleep(wait_time) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "90fb2fa7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd second.\n",
      "This second seems a little odd.\n",
      "Not an odd second.\n",
      "This second seems a little odd.\n",
      "Not an odd second.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import time\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "         print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "         print(\"Not an odd second.\")\n",
    "    time.sleep(1) # 暂停1秒输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2e20319b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter the datetime:(20170228):20220422\n",
      "112\n"
     ]
    }
   ],
   "source": [
    "# 输入某年某月某日 判断该日是这一年的第几天？\n",
    "import datetime # 导入时间模块\n",
    "dtstr = input(\"Enter the datetime:(20170228):\") # 输入某年某月某日\n",
    "dt = datetime.datetime.strptime(dtstr,\"%Y%m%d\")\n",
    "another_dtstr = dtstr[:4] + \"0101\"\n",
    "another_dt = datetime.datetime.strptime(another_dtstr,\"%Y%m%d\")\n",
    "print(int((dt - another_dt).days) + 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1d16b616",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd second.\n",
      "Not an odd second.\n",
      "Not an odd second.\n",
      "Not an odd second.\n",
      "Not an odd second.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import time\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    right_this_second = time.asctime # 格式化当前时间\n",
    "    if right_this_second in odds:\n",
    "         print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "         print(\"Not an odd second.\")\n",
    "    time.sleep(1) # 暂停1秒输出\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bdb7c6c6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f986a8a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
